package com.zhuiyun.project.api.audio.controller;

import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.audio.entity.Audio;
import com.zhuiyun.project.api.audio.service.AudioService;
import com.zhuiyun.project.common.controller.BaseController;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.UploadFileUtils;
import com.zhuiyun.project.utils.constants.CommonConstants;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName audioController
 * @Description TODO
 * @Author Administrator
 * @Date 2023/11/22 10:49
 **/
@RestController
@RequestMapping("/audio")
public class AudioController extends BaseController {

    @Autowired
    private AudioService audioService;

    /**
    * @Author Administrator
    * @Description 音频全查
    * @Date 2023/11/22 10:53
    * @Return com.zhuiyun.project.common.response.CommonResult
    */
    @PreAuthorize("@ss.hasPermi('audio:list')")
    @ApiOperation(value = "音频的全查方法")
    @OptLog(modular = "音频管理", type = CommonConstants.SELECT, describe = "音频的全查方法")
    @GetMapping("/listAudio")
    public CommonResult listAudio(PageRequest pageRequest, Audio audio){
        return CommonResult.ok(audioService.listAudio(pageRequest, audio));
    }
    /**
    * @Author Administrator
    * @Description 添加音频
    * @Date 2023/11/22 15:50
    * @Return com.zhuiyun.project.common.response.CommonResult
    */
    @PreAuthorize("@ss.hasPermi('audio:add')")
    @ApiOperation(value = "音频的添加方法")
    @OptLog(modular = "音频管理", type = CommonConstants.ADD, describe = "音频的添加方法")
    @PostMapping("/insertAudio")
    public CommonResult insertAudio(@RequestBody Audio audio) {
        return CommonResult.ok(audioService.insertAudio(audio));
    }

    /**
    * @Author Administrator
    * @Description 根据id查询音频
    * @Date 2023/11/22 18:52
    * @Return com.zhuiyun.project.common.response.CommonResult
    */
    @PreAuthorize("@ss.hasPermi('audio:select')")
    @ApiOperation(value = "根据音频编号获取信息")
    @OptLog(modular = "音频管理",type = CommonConstants.SELECT, describe = "根据音频编号获取信息")
    @GetMapping("/{audioId}")
    public CommonResult getAudio(@PathVariable("audioId") Integer audioId){
        return CommonResult.ok(audioService.getAudio(audioId));
    }
    /**
    * @Author Administrator
    * @Description 删除音频
    * @Date 2023/11/22 19:55
    * @Return com.zhuiyun.project.common.response.CommonResult
    */
    @PreAuthorize("@ss.hasPermi('audio:remove')")
    @ApiOperation(value = "音频管理的删除方法")
    @OptLog(modular = "音频管理", type = CommonConstants.DELETE, describe = "删除音频")
    @DeleteMapping("/{audioIds}")
    public CommonResult removeAudio(@PathVariable Integer[] audioIds){
        return audioService.removeAudio(audioIds);
    }
    /**
    * @Author Administrator
    * @Description 音频上传
    * @Date 2023/11/23 18:49
    * @Return com.zhuiyun.project.common.response.CommonResult
    */
    @ApiOperation(value = "音频上传")
    @PostMapping("/upload")
    public CommonResult uploadAudio(MultipartFile file){
        String audioId = UploadFileUtils.uploadFile(file);
        return CommonResult.ok(audioId);
    }
    /**
    * @Author Administrator
    * @Description 修改音频状态
    * @Date 2023/11/23 20:58
    * @Return com.zhuiyun.project.common.response.CommonResult
    */
    @ApiOperation(value = "音频状态修改")
    @OptLog(modular = "音频管理",type = CommonConstants.UPDATE,describe = "音频状态修改")
    @PreAuthorize("@ss.hasPermi('audio:edit')")
    @PutMapping("/setAudioStatus")
    public CommonResult setAudioStatus(@RequestBody Audio audio){
        return CommonResult.ok(audioService.setStatus(audio));
    }

    /**
     * @Author Administrator
     * @Description 查询音频类型数量
     * @Date 2023/11/25 10:56
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @ApiOperation(value = "查询音频类型数量")
    @OptLog(modular = "音频管理",type = CommonConstants.SELECT,describe = "查询音频类型数量")
    @PreAuthorize("@ss.hasPermi('audio:select')")
    @GetMapping("/getNumByAudioType/{audioType}")
    public CommonResult getNumByAudioType(@PathVariable(required = true) Integer audioType) {

        return CommonResult.ok(audioService.getNumByAudioType(audioType));
    }
}
